<script setup lang="ts">
import { computed, getCurrentInstance, onMounted, ref } from 'vue'
import { Message } from 'element-ui'
import DetailTable from '@/views/project-update/project-ledger/financial-ledger/detail-table.vue'
import { getProjectLedgerFinanceDetail } from '@/api/project-update/project-ledger'
import { queryArea } from '@/api/question'
import Download from '@/views/project-update/components/download.vue'
import { PERMISSIONS } from '@/common/user'

const vm = getCurrentInstance()

const route = vm.proxy.$route
const router = vm.proxy.$router
const currentUser = vm.proxy.$store.state.user.currentUser

const handleCancel = () => {
  router.go(-1)
}

const params = route.query
const { regionId, projectId, projectName } = params

const detailTableRef = ref()

const cityList = ref([])

const getArea = () => {
  queryArea({}).then((res) => {
    if (res.success) {
      cityList.value = res.data[0].children
    } else {
      Message.error(res.message)
    }
  })
}

const areaName = computed(() => {
  return cityList.value.find((item) => item.pkid === regionId)?.areaName
})

onMounted(() => {
  getArea()
  if (!projectId) return
  getProjectLedgerFinanceDetail({
    projectId,
    regionId,
  }).then((res) => {
    if (res.success) {
      detailTableRef.value.inputData(res.data)
    } else {
      Message.error(res.message)
    }
  })
})

const detailDownloadParams = [
  {
    regionId,
    projectId,
  },
]
</script>

<template>
  <div class="add-annual-plan">
    <div class="nav">
      <div class="breadcrumb">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/project-update/financial-ledger' }"
            ><span class="breadcrumb-title">列表</span></el-breadcrumb-item
          >
          <el-breadcrumb-item>详情</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>
    <div class="content">
      <div class="content-main">
        <div class="fill-title">
          <!--          <el-date-picker v-model="month" type="month" placeholder="选择月">-->
          <!--          </el-date-picker-->
          <!--          >-->
          {{ areaName }}{{ projectName }}金融台账
        </div>
        <div class="fill-remark"></div>
        <detail-table ref="detailTableRef" />
      </div>
      <div class="buttons">
        <el-button class="cancel" @click="handleCancel">取消</el-button>
        <download
          type="finance-detail"
          :params="detailDownloadParams"
          :permission="PERMISSIONS.金融台账详情下载"
        />
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.add-annual-plan {
  width: calc(100% - 40px);
  height: calc(100% - 40px);
  padding: 20px;
  background-color: rgba(244, 248, 254, 1);

  .content {
    width: calc(100% - 40px);
    height: calc(100% - 70px);
    position: absolute;
    top: 65px;
    bottom: 0;

    .divider {
      width: 100%;
      height: 1px;
      background: #e7f0ff;
      border-radius: 1px 1px 0px 0px;
      margin: 20px 0;
    }

    .content-main {
      height: calc(100% - 100px);
      background: #ffffff;
      box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.1);
      border-radius: 2px;
      padding: 13px 16px 13px 16px;
      overflow-y: auto;

      .fill-title {
        width: 100%;
        height: 40px;
        line-height: 40px;
        font-size: 16px;
        font-weight: 500;
        text-align: center;
      }

      .fill-remark {
        height: 16px;
        margin-top: 10px;
        margin-bottom: 10px;
      }
    }

    .buttons {
      padding: 10px;
      display: flex;
      justify-content: center;
      background: #ffffff;
      box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.1);

      .el-button {
        width: 110px;
      }

      .cancel {
        background: #ffffff;
        border-radius: 4px;
        border: 1px solid #e7f0ff;
        font-weight: 400;
        font-size: 16px;
        color: #8894a8;
      }

      .save {
        //background: #10a6dd;
        border-radius: 4px;
        //color: #ffffff;
      }

      .publish {
        //background: #ffffff;
        border-radius: 4px;
        //color: #10a6dd;
        //border: 1px solid #10a6dd;
      }
    }
  }
}
</style>
